package com.example.wm.consumer;

import com.example.wm.constants.KafkaConstants;
import com.example.wm.models.Container;
import com.example.wm.models.Storage;
import com.example.wm.service.WebSocketNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class StorageListener {

    @Autowired
    private WebSocketNotificationService notificationService;

    @KafkaListener(topics = KafkaConstants.ELEVATOR_TOPIC,
                    groupId = KafkaConstants.GROUP_ID
    )
    public void listen(Storage message) {


        if(message.getCurrentUsage() == -1){
            System.out.println("Storage failed because of exceeding the maximum capacity:"+message);
            notificationService.notifyFrontend("Storage failed: Exceeded maximum capacity.");
        }else if(message.getCurrentUsage() != 0) {
                System.out.println("Storage successes information:"+message);
                notificationService.notifyFrontend("Storage successes information: " + message);
        }
    }
}
